package com.example.star.mapper;

import com.example.star.entity.Perimeter;
import com.example.star.entity.Star;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PerimeterMapper {

    @Insert("INSERT INTO perimeters (username,imageResource, starName, title, productType, prices, freight, deliveryAddress) " +
            "VALUES (#{userName},#{imageResource}, #{starName}, #{title}, #{productType}, #{prices}, #{freight}, #{deliveryAddress})")
    void insertPerimeter(Perimeter perimeter);

    @Select("SELECT * FROM perimeters")
    List<Perimeter> getAllPerimeters();

    @Delete("DELETE FROM perimeters WHERE id = #{id}")
    void deletePerimeter(int id);

    @Select("SELECT * FROM perimeters WHERE id = #{id}")
    Perimeter getPerimeterById(int id);

    @Update("UPDATE perimeters SET imageResource = #{imageResource}, starName = #{starName}, title = #{title}, productType = #{productType}, prices = #{prices}, freight = #{freight}, deliveryAddress = #{deliveryAddress} WHERE id = #{id}")
    void updatePerimeter(Perimeter perimeter);

    @Select("SELECT * FROM perimeters LIMIT #{offset}, #{limit}")
    List<Perimeter> getPerimetersByPage(@Param("offset") int offset, @Param("limit") int limit);
    @Select("SELECT COUNT(*) FROM perimeters")
    int getTotalPerimeters();

}